#include"Heap.h"

void HeapCreate(Heap* hp) {
	HPDataType* arr;
	arr = (HPDataType*)malloc(sizeof(HPDataType) * 4);
	hp->_arr = arr;
	hp->_capacity = 4;
	hp->_size = 0;
}
void  swap(int* f, int* c) {
	int tmp;
	tmp = *c;
	*c = *f;
	*f = tmp;
}
void AdjustUp(HPDataType* arr, int child) {
	int fathr = (child - 1) / 2;
	while (fathr>=0){
		if (arr[child] < arr[fathr]) {
			swap(&arr[child], &arr[fathr]);
			child = fathr;
			fathr = (child - 1) / 2;
		}
		else{
			break;
		}
	}
}
void HeapDestory(Heap* hp) {
	free(hp->_arr);
	hp->_arr = NULL;
}
void HeapPush(Heap* hp, HPDataType x) {
	hp->_arr[hp->_size] = x;
	hp->_size++;
	AdjustUp(hp->_arr, hp->_size);
}